﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DatabaseConnectionExample
{
    class Program
    {
        static void Main(string[] args)
        {
            TimeSpan timeout = new TimeSpan(1000);
            MySqlConnection mySqlConnection = new MySqlConnection("111", timeout);

            MsSqlConnection msSqlConnection = new MsSqlConnection("222", timeout);

            DatabaseCommand command = new DatabaseCommand(msSqlConnection, "Some SQL");

            command.Execute();
        }
    }

    class DatabaseCommand
    {
        private readonly DatabaseConnection dbConnection;
        private readonly string sqlString;

        public DatabaseCommand(DatabaseConnection connection, string sql)
        {
            if (connection == null)
            {
                throw new NullReferenceException("connection");
            }
            if (String.IsNullOrWhiteSpace(sql))
            {
                throw new ArgumentException("sql");
            }
            sqlString = sql;
            dbConnection = connection;
        }

        public void Execute()
        {
            dbConnection.OpenConnection();
            Console.WriteLine("Exetute SQL command: {0}", sqlString);
            dbConnection.CloseConnection();
        }
    }
}
